Package gri.tasks.gui

Source Code of gri.tasks.gui.TaskInputPanel

/*
* File: TaskInputPanel.java
* Author: Daniel Rogers
* Created on Apr 28, 2008
*
*/
package gri.tasks.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

import gri.tasks.ParameterDef;

import gri.tasks.managers.TaskDescription;

import gri.tasks.gui.widgets.ParameterWidgetFactory;

import dan.swing.JPrettyButton;
import dan.swing.style.AppStyles;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;

/**
* Panel which displays the input form for a task.  This task
* is given as a TaskEntry object from which we will obtain a
* TaskDescription and task definition.  An "execute" button is
* displayed but does nothing.  Instead, ActionListener's may be
* notified when this button is clicked to handle it as needed.
*/
public class TaskInputPanel extends JPanel implements ActionListener {

  TaskDescription taskDesc;
  ParameterDef [] paramDefs;
  ParameterWidgetFactory widgetFactory;

  TaskHeaderPanel headerPanel;
  ParameterPanel paramPanel;
  JPanel pnlButtons;

  JButton btnExecute;
  List listeners = new ArrayList(3);

  // -------------------------------------------------- Constructors

  public TaskInputPanel(TaskDescription taskDesc, ParameterDef [] paramDefs, ParameterWidgetFactory widgetFactory, boolean displayExecButton) {
    super(null);

    this.taskDesc = taskDesc;
    this.paramDefs = paramDefs;
    this.widgetFactory = widgetFactory;

    init(displayExecButton);
  }
  public TaskInputPanel(TaskDescription taskDesc, ParameterDef [] paramDefs, ParameterWidgetFactory widgetFactory) {
    this(taskDesc, paramDefs, widgetFactory, true);
  }

  // ----------------------------------------------------- Accessors

  public void addExecutionListener(ActionListener l) {
    listeners.add(l);
  }
  public void removeExecutionListener(ActionListener l) {
    listeners.remove(l);
  }

  public ParameterPanel getParameterPanel()  {return paramPanel;}
  public JButton getExecuteButton()    {return btnExecute;}

  public void setValue(String name, Object value) {
    paramPanel.setValue(name, value);
  }
  public void setValues(Map values) {
    paramPanel.setValues(values);
  }

  public Map getValues() {
    return paramPanel.getValues();
  }
  public Object getValue(String name) {
    return paramPanel.getValue(name);
  }

  // ------------------------------------------------- Implementation

  protected void init(boolean displayExecButton) {
    super.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    //header:
    headerPanel = new TaskHeaderPanel();
    headerPanel.setTaskDescription(taskDesc);
    Dimension dim = headerPanel.getPreferredSize();
    headerPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));
    AppStyles.applyStyle(headerPanel, "TaskHeaderPanel");
    add(headerPanel);

    //parameters:
    paramPanel = new ParameterPanel(paramDefs, widgetFactory);
    dim = paramPanel.getPreferredSize();
    paramPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));
    AppStyles.applyStyle(paramPanel, "ParameterPanel");
    add(paramPanel);

    add(Box.createVerticalGlue());

    //buttons:
    btnExecute = new JPrettyButton("Run");
    AppStyles.applyStyle(btnExecute, "ParameterPanel button.run");
    btnExecute.addActionListener(this);
    dim = btnExecute.getPreferredSize();
    btnExecute.setPreferredSize(new Dimension(dim.width * 5, dim.height));
    btnExecute.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));

    pnlButtons = new JPanel(new BorderLayout());
    pnlButtons.add(btnExecute, BorderLayout.CENTER);
    dim = pnlButtons.getPreferredSize();
    pnlButtons.setMaximumSize(new Dimension(Integer.MAX_VALUE, dim.height));

    if (displayExecButton)
      add(pnlButtons);
  }

  public void actionPerformed(ActionEvent e) {
    for (int i=0; i<listeners.size(); i++)
      ((ActionListener)listeners.get(i)).actionPerformed(e);
  }
TOP

Related Classes of gri.tasks.gui.TaskInputPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.